package com.ruoyi.web.controller.insect.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.insect.domain.DiseaseInfo;
import com.ruoyi.insect.service.IDiseaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 病虫害信息查询Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/insect/info")
public class DiseaseInfoController extends BaseController
{
    @Autowired
    private IDiseaseInfoService diseaseInfoService;

    /**
     * 查询病虫害信息查询列表
     */
    @PreAuthorize("@ss.hasPermi('insect:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(DiseaseInfo diseaseInfo)
    {
        startPage();
        List<DiseaseInfo> list = diseaseInfoService.selectDiseaseInfoList(diseaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出病虫害信息查询列表
     */
    @PreAuthorize("@ss.hasPermi('insect:info:export')")
    @Log(title = "病虫害信息查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DiseaseInfo diseaseInfo)
    {
        List<DiseaseInfo> list = diseaseInfoService.selectDiseaseInfoList(diseaseInfo);
        ExcelUtil<DiseaseInfo> util = new ExcelUtil<DiseaseInfo>(DiseaseInfo.class);
        util.exportExcel(response, list, "病虫害信息查询数据");
    }

    /**
     * 获取病虫害信息查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('insect:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(diseaseInfoService.selectDiseaseInfoById(id));
    }

    /**
     * 新增病虫害信息查询
     */
    @PreAuthorize("@ss.hasPermi('insect:info:add')")
    @Log(title = "病虫害信息查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DiseaseInfo diseaseInfo)
    {
        return toAjax(diseaseInfoService.insertDiseaseInfo(diseaseInfo));
    }

    /**
     * 修改病虫害信息查询
     */
    @PreAuthorize("@ss.hasPermi('insect:info:edit')")
    @Log(title = "病虫害信息查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiseaseInfo diseaseInfo)
    {
        return toAjax(diseaseInfoService.updateDiseaseInfo(diseaseInfo));
    }

    /**
     * 删除病虫害信息查询
     */
    @PreAuthorize("@ss.hasPermi('insect:info:remove')")
    @Log(title = "病虫害信息查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(diseaseInfoService.deleteDiseaseInfoByIds(ids));
    }
}
